#include "string_utils.h"


std::vector<std::string> SplitString(const std::string& string, char delim)
{
    std::vector<std::string> elems;
    std::string::size_type prev, pos;

    prev = -1;
    pos = string.find(delim);
    if (pos == std::string::npos) {
        elems.push_back(string);
        return elems;
    }
    while (pos != std::string::npos) {
        elems.push_back(string.substr(prev + 1, pos - prev - 1));
        prev = pos;
        pos = string.find(delim, prev + 1);
    }

    elems.push_back(string.substr(prev + 1));

    return elems;
}


std::string JoinString(const std::string& separator, const std::vector<std::string>& strings)
{
    std::string out{};

    for (auto & sub_string : strings) {
        out.append(sub_string + separator);
    }

    out.erase(out.end() - separator.length(), out.end());

    return out;
}